package com.fxu.gen.enums;

import cn.hutool.core.util.StrUtil;

import java.io.File;

/**
 * 各个生成文件自属性
 * @author fangxu
 */
public enum TplEnum {
	SQL("SQL语句"),
	Entity("数据实体类"),
	Enums("数据实体枚举类"),
	Feign("远程调用Feign类"),
	FeignFallback("远程调用Feign类熔断错误类"),
	Service("服务业务逻辑接口"),
	ServiceImpl("服务业务逻辑实现"),
//	ServiceImplTest("服务业务逻辑实现测试"),
	RestImpl("业务逻辑接口实现"),
	RestService("业务逻辑接口实现"),
	RestServiceImpl("业务逻辑接口实现"),
//	RestServiceImplTest("业务逻辑接口实现测试"),
	Mapper("数据库操作接口"),
	MapperXml("数据库操作XML"),
	Controller("Restfull接口"),
	VueHtml("vue前端界面"),
	VbenVue3("vben-admin界面"),
	VbenAdmin("vben-admin界面"),
	PageReq("Entity分页请求");
	
	private final String cmmt;

	TplEnum(String cmmt) {
        this.cmmt = cmmt;
    }

    public String getCmmt() {
        return cmmt;
    }

	public String getName(String tplClassName) {
		if (this == Entity || this == SQL) {
			return tplClassName + ".java";
		} else if (this == Enums) {
			return tplClassName + "TypeEnum.java";
		} else if (this == MapperXml) {
			return tplClassName + "Mapper.xml";
		} else if (this == VueHtml || this == VbenAdmin || this == VbenVue3) {
			return StrUtil.lowerFirst(tplClassName) + ".vue";
		}
//		else if (this == ServiceImplTest) {
//			return tplClassName + "Test.java";
//		} else if (this == RestServiceImplTest) {
//			return tplClassName + "RestTest.java";
//		}
		else {
			return tplClassName + this + ".java";
		}
	}
	
	public String getSrcPath(String project, String module) {
		switch (this) {
		case Entity:
			return String.format("src/main/java/com/%s/%s/entity/", project, module);
		case PageReq:
			return String.format("src/main/java/com/%s/%s/dto/", project, module);
		case Enums:
			return String.format("src/main/java/com/%s/%s/enums/", project, module);
		case Feign:
			return String.format("src/main/java/com/%s/%s/feign/", project, module);
		case FeignFallback:
			return String.format("src/main/java/com/%s/%s/feign/fallback/", project, module);
		case Service:
			return String.format("src/main/java/com/%s/%s/service/", project, module);
		case ServiceImpl:
			return String.format("src/main/java/com/%s/%s/service/impl/", project, module);
		case RestImpl:
			return String.format("src/main/java/com/%s/%s/rest/", project, module);
		case RestService:
			return String.format("src/main/java/com/%s/%s/rest/service/", project, module);
		case RestServiceImpl:
			return String.format("src/main/java/com/%s/%s/rest/service/impl/", project, module);
		case Mapper:
			return String.format("src/main/java/com/%s/%s/mapper/", project, module);
		case MapperXml:
			return String.format("src/main/resources/mybaits/", project, module);
		case Controller:
			return String.format("src/main/java/com/%s/%s/api/", project, module);
		default:
			break;
		}
		return null;
	}

	//TODO 优化比较Enums
	public String getPath(String project, int projectType, String module) {
		switch (this) {
		case Entity:
			return String.format("%s-%s/src/main/java/com/%s/%s/entity/", project, projectType == 1 ? module : "facade", project, module);
		case Feign:
			return String.format("%s-%s/src/main/java/com/%s/%s/feign/", project, projectType == 1 ? module : "facade", project, module);
		case FeignFallback:
			return String.format("%s-%s/src/main/java/com/%s/%s/feign/fallback/", project, projectType == 1 ? module : "facade", project, module);
		case Service:
			return String.format("%s-%s/src/main/java/com/%s/%s/service/", project, projectType == 1 ? module : "facade", project, module);
		case ServiceImpl:
			return String.format("%s-%s/src/main/java/com/%s/%s/service/impl/", project, module, project, module);
		case RestImpl:
//			return String.format("%s-%s/src/main/java/com/%s/%s/rest/impl/", project, module, project, module);
			return String.format("%s-%s/src/main/java/com/%s/%s/rest/", project, module, project, module);
		case RestService:
			return String.format("%s-%s/src/main/java/com/%s/%s/rest/service/", project, module, project, module);
		case RestServiceImpl:
			return String.format("%s-%s/src/main/java/com/%s/%s/rest/service/impl/", project, module, project, module);
		case Mapper:
			return String.format("%s-%s/src/main/java/com/%s/%s/mapper/", project, module, project, module);
		case MapperXml:
			return String.format("%s-%s/src/main/resources/mybaits/", project, module, project, module);
		case Controller:
//			return String.format("%s-%s/src/main/java/com/%s/%s/controller/", project, module, project, module);
			return String.format("%s-%s/src/main/java/com/%s/%s/api/", project, module, project, module);
		default:
			break;
		}
		return null;
	}
	
	public final static TplEnum get(String tplClassName, File file) {
		if (file == null || !file.isFile() || !file.exists()) return null;
		for (TplEnum tfe : TplEnum.values()) {
			if (file.getName().endsWith(tfe.getName(tplClassName))) {
				return tfe;
			}
		}
		return null;
    }
    
    public final static boolean isInterface(TplEnum tplEnum) {
        return tplEnum != null && (tplEnum == Feign || tplEnum == RestService); // || tplEnum == Service || tplEnum == Mapper
    }
}
